<?php

App::uses('AppModel', 'Model');

class KalkulatorPorez extends AppModel {
    
    public $useTable = 'kalkulator_porez';
    
    public function calculate($data) {
        $value = 0;
        $row = $this->find('first', array(
            'fields'     => array('value'),
            'conditions' => array(
                'vrsta_vozila' => $data['vrsta_vozila'],
                'god_od <=' => $data['godiste'],
                'god_do >=' => $data['godiste'],
                'min <='    => (float)$data['zapremina'],
                'max >='   => (float)$data['zapremina']
            )
        ));
        if ($row) {
            $value = (float)$row[$this->name]['value'];
        }
        
        // ZA TAXI -50%
        if ($data['taxi']) {
            $value *= 0.5;
        }
        
        // invalidi -100%
        if ($data['invalid']) {
            $value = 0;
        }
        
        return $value;
    }
    
}
